<?php

class IndexController extends Zend_Controller_Action
{

    /**
     * FlashMessenger
     *
     * @var Zend_Controller_Action_Helper_FlashMessenger
     */
    protected $_flashMessenger = null;

    /**
     * Текущая локаль.
     * @var string
     */
    protected $_locale;

    public function init()
    {

        $this->_helper->layout()->setLayout('index-layout');

        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');

        $localeSession = new Zend_Session_Namespace('locale');
        $this->_locale = $localeSession->locale;

        $pagesManager = new \Managers\Pages();
        $pages = $pagesManager->all($this->_locale, true);

        $menusManager = new \Managers\Menu();
        $menu = $menusManager->all();
        
        $this->view->pages = $pages;
        $this->view->menu = $menu;

    }

    public function indexAction()
    {

        $this->_forward('page');

    }


    public function pageAction()
    {

        $id = $this->_getParam('id');
        $pagesManager = new \Managers\Pages();

        $page = $pagesManager->oneTranslation($this->_locale, $id);

        if (!$id) {

            $translatesManager = new \Managers\Translates();
            $id = $translatesManager->page($page[0]['id']);
        }

        if ($id == 1) {
            $this->view->banner = 1;
        }

        $this->view->page = $page[0];
        $this->view->current = $id;

    }

    public function localeAction()
    {

        $locale = $this->_getParam('locale');

        if (isset($locale)) {

            $localeSession = new Zend_Session_Namespace('locale');

            $localeSession->locale = $locale;
        }

        $this->_redirect('/');
    }


}
